package com.superman.supermarket.client.composite.orderlist;

import java.util.List;
import java.util.Map;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.json.client.JSONArray;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.composite.preorder.PreorderStoreModule;
import com.superman.supermarket.client.event.PreorderPageEvent;
import com.superman.supermarket.client.event.PreorderPageEvent.PreorderPageEventType;

/**
 * 订单列表店铺模块
 * 
 * @author superman
 * @version 2018年8月12日下午5:05:57
 */
public class OrderListStoreModule extends PreorderStoreModule {
	private String storeId;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月12日 下午5:06:34
	 */
	public OrderListStoreModule() {
		memo.removeFromParent();

		storepanel.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				XGinjector.INSTANCE.getEventbusController().fire(new PreorderPageEvent(storeId, PreorderPageEventType.CLICK_STORE));
			}
		}, ClickEvent.getType());
	}

	@Override
	public void setData(Map<String, Object> map) {
		this.storeId = String.valueOf(map.get("STORE_ID"));
		storelogo.setUrl(String.valueOf(map.get("STORE_LOGO")));
		storenamehtml.setText(String.valueOf(map.get("STORE_NAME")));

		skulistpanel.clear();
		List<Map<String, Object>> skuList = XJsonUtil.getList((JSONArray) map.get("SKU_LIST"));
		for (Map<String, Object> sku : skuList) {
			if (map.get("ORDER_ID") != null)
				sku.put("ORDER_ID", map.get("ORDER_ID"));
			OrderListSkuModule orderListSkuModule = new OrderListSkuModule();
			orderListSkuModule.setData(sku);
			skulistpanel.add(orderListSkuModule);
		}
	}

}
